package MyApp.View.well
{
	import MyApp.Model.WellObsRecord;
	import MyApp.Model.proxy.WellProxy;
	import MyApp.MyAppFacade;
	
	import components.well.UpdateObsRecord;
	import components.well.WellWindow;
	
	import flash.events.MouseEvent;
	
	import mx.events.CloseEvent;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	import util.GDUtil;
	
	public class UpdateObsRecordMediator extends Mediator
	{
		public static const NAME:String=GDUtil.getUID();
		public function UpdateObsRecordMediator(mediatorName:String=null, viewComponent:Object=null)
		{
			super(mediatorName, viewComponent);
			view.addEventListener(CloseEvent.CLOSE,doClose);
			view.addEventListener(UpdateObsRecord.DO_SAVE,doSave);
		}
		private function get view():UpdateObsRecord{
			return viewComponent as UpdateObsRecord;
		}
		protected function doSave(e:MouseEvent):void{
			view.currentState="loading";
			var record:WellObsRecord=view.record;
			this.sendNotification(WellWindow.DO_UPDATE_OBSRECORD,{record:record,pager:view.pager});
		}
		protected function doClose(e:CloseEvent):void{
			MyAppFacade.closePopUpWindow(view,NAME);
		}
		override public function listNotificationInterests():Array{
			return [WellProxy.UPDATE_OBS_RECORD_OK];
		}
		override public function handleNotification(notification:INotification):void{
			switch(notification.getName()){
				case WellProxy.UPDATE_OBS_RECORD_OK:
					MyAppFacade.closePopUpWindow(view,NAME);
					break;
			}
		}
	}
}